package com.zd.springcloud.provider.mapper;


import com.zd.springcloud.base.BaseMapper;
import com.zd.springcloud.domain.Good;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;



public interface GoodMapper extends BaseMapper {

    @Select("select * from t_good where id = #{goodId}")
    Good findGoodById(Long goodId);


    //减库存和预留资源， 库存字段减，预留资源字段加
    @Update("update t_good set good_stock = good_stock -#{num} , good_reduce = good_reduce + #{num} where id = #{goodId}")
    void reduceStock(@Param("num") int num, @Param("goodId")Long goodId);


    //删除预留资源， 预留资源字段减
    @Update("update t_good set  good_reduce = good_reduce - #{num} where id = #{goodId}")
    void reduceCommit(@Param("num") int num, @Param("goodId")Long goodId);


    //减的库存 + 回来,预留字段减回去
    @Update("update t_good set  good_stock = good_stock + #{num}, good_reduce = good_reduce - #{num} where id = #{goodId}")
    void stockRollback(@Param("num") int num, @Param("goodId")Long goodId);



}
